/**
 * Created by Administrator on 2015/11/9 0009.
 */
var express = require('express');
var router = express.Router();
var BaseModel = require('../models/base_model');
var baseModel = new BaseModel();


router.get('/', function(req, res, next) {
    res.render('login', {
        title: '登录'
    });
});

router.post('/', function (req, res) {
    var tableName = 'login_log';
    var date = new Date();
    var rowInfo = {
        'user':req.body.name,
        'time':date
    };
    var uname = req.body.name;
    var pwd = req.body.password;
    var sql =  "select name,password from user where name='"+uname+"' and password='"+pwd+"'";
    baseModel.findOneById(sql,function(ret){
         console.log(ret);
         if(!ret){
             return res.render('login',{
                 title:'登录',
                 message:'用户或密码错误'
             });
         }else {
               res.cookie('IP', 'name='+ret.name, {maxAge:100000*6000, path:'/', httpOnly:true});
               baseModel.insert(tableName, rowInfo, function (ret) {
               return res.redirect('/zy');
             });
         }
   });
});

module.exports = router;



